/**
 * Created by Administrator on 2017/4/6 0006.
 */
var React = require('react');

module.exports = React.createClass({
    getInitialState: function () {
        return {
            flag: "",
            photoUrl:[],//图片地址
        }
    },

    componentDidMount: function () {

    },
    //取消选择图片
    cancelPhoto(){
        var flag = this.state.flag;
        if(flag){
            this.setState({flag:false})
        }
    },
    //拍照
    photoGraph(){
        var p=this;
        if(window.jsbridge){
            window.jsbridge.takePhoto();
            window.takePhotoCallBack=function(e){
                if(e){
                    p.setState({photoUrl:e});
                    p.props.picUrl();
                }
            };
        }
        this.cancelPhoto();
    },
    //访问相册
    photoAlbum(){
        var p=this;
        if(window.jsbridge){
            window.jsbridge.selectPic();
            window.takePhotoCallBack=function(e){
                if(e){
                    p.setState({photoUrl:e});
                    p.props.picUrl();
                }
            };
        }
        p.cancelPhoto();
    },

    render: function () {
        var p =this;
        return (
            <div className={p.state.flag ? "user_bottom ad":"user_bottom"}>
                <div className={p.state.flag ? "get-photo ad1":"get-photo"}>
                    <div className="photo-s border-s">
                        <div className="bot-s bot-p" onClick={p.photoGraph}>
                            <span className="photo-c">拍照</span>
                        </div>
                        <div className="bot-s" onClick={p.photoAlbum}>
                            <span className="photo-c">从相册中选取</span>
                        </div>
                    </div>
                    <div className="bot-s border-s" onClick={p.cancelPhoto}>
                        <span className="cancel-c">取消</span>
                    </div>
                </div>
            </div>
        )
    }
});
